package com.ruoyi.web.controller.item;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.item.domain.ItemSkuSpu;
import com.ruoyi.item.service.IItemSkuSpuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 京东SKU与SPU对照Controller
 * 
 * @author ruoyi
 * @date 2022-03-23
 */
@Api("京东SKU与SPU对照Controller")
@RestController
@RequestMapping("/item/skuspu")
public class ItemSkuSpuController extends BaseController
{
    @Autowired
    private IItemSkuSpuService itemSkuSpuService;

    /**
     * 查询京东SKU与SPU对照列表
     */
    @ApiOperation("查询京东SKU与SPU对照列表")
    @PreAuthorize("@ss.hasPermi('item:skuspu:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemSkuSpu itemSkuSpu)
    {
        startPage();
        List<ItemSkuSpu> list = itemSkuSpuService.selectItemSkuSpuList(itemSkuSpu);
        return getDataTable(list);
    }

    /**
     * 导出京东SKU与SPU对照列表
     */
    @ApiOperation("导出京东SKU与SPU对照列表")
    @PreAuthorize("@ss.hasPermi('item:skuspu:export')")
    @Log(title = "京东SKU与SPU对照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemSkuSpu itemSkuSpu)
    {
        List<ItemSkuSpu> list = itemSkuSpuService.selectItemSkuSpuList(itemSkuSpu);
        ExcelUtil<ItemSkuSpu> util = new ExcelUtil<ItemSkuSpu>(ItemSkuSpu.class);
        util.exportExcel(response, list, "京东SKU与SPU对照数据");
    }

    /**
     * 获取京东SKU与SPU对照详细信息
     */
    @ApiOperation("获取京东SKU与SPU对照详细信息")
    @PreAuthorize("@ss.hasPermi('item:skuspu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(itemSkuSpuService.selectItemSkuSpuById(id));
    }

    /**
     * 新增京东SKU与SPU对照
     */
    @ApiOperation("新增京东SKU与SPU对照")
    @PreAuthorize("@ss.hasPermi('item:skuspu:add')")
    @Log(title = "京东SKU与SPU对照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemSkuSpu itemSkuSpu)
    {
        return toAjax(itemSkuSpuService.insertItemSkuSpu(itemSkuSpu));
    }

    /**
     * 修改京东SKU与SPU对照
     */
    @ApiOperation("修改京东SKU与SPU对照")
    @PreAuthorize("@ss.hasPermi('item:skuspu:edit')")
    @Log(title = "京东SKU与SPU对照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemSkuSpu itemSkuSpu)
    {
        return toAjax(itemSkuSpuService.updateItemSkuSpu(itemSkuSpu));
    }

    /**
     * 删除京东SKU与SPU对照
     */
    @ApiOperation("删除京东SKU与SPU对照")
    @PreAuthorize("@ss.hasPermi('item:skuspu:remove')")
    @Log(title = "京东SKU与SPU对照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(itemSkuSpuService.deleteItemSkuSpuByIds(ids));
    }
}
